<?php

namespace App\Http\Controllers\Home;

use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

class RoleController extends Controller
{
    public function role(){
        $role = Role::create(['name' => 'admin','guard_name' => 'web']);
        $role = Role::create(['name' => 'leader','guard_name' => 'web']);
        $role = Role::create(['name' => 'staff','guard_name' => 'web']);
        $role = Role::create(['name' => 'external','guard_name' => 'web']);
        $role = Role::create(['name' => 'recommend','guard_name' => 'web']);
    }

    public function test(){
        $users = User::where('status',1)->with('frame')->get();
        foreach ($users as $v){
            if ($v->type == 1){
                if ($v->frame){
                    switch ($v->frame->level ){
                        case 1:
                            $v->assignRole('admin');
                            break;
                        case 2:
                            $v->assignRole('leader');
                            break;
                        case 3:
                            $v->assignRole('staff');
                            break;
                    }
                }
            }elseif ($v->type == 2){
                $v->assignRole('external');
            }elseif ($v->type == 3){
                $v->assignRole('recommend');
            }
        }
    }
    public function utest(){
        $aa = Hash::make('12345678');
        dd($aa);
        $user = User::where('status',1)->first();
        dd($user->getRoleNames(),$user->hasAnyRole(['staff','external']));
    }

}
